<template>
  <div>
    商品详情
    <el-row>
      <el-col :span="8">
        <img :src="'/project/img/'+ productObj.imgPath">
      </el-col>
      <el-col :span="16">
        <div>商品名：{{ productObj.name }}</div>
        <div>单价：{{ productObj.price }}</div>
        <div>产地：{{ productObj.createAddr }}</div>
        <div>生产日期：{{ productObj.createDate }}</div>
        <div>已售出{{ productObj.salesNum }}件</div>
        <el-button type="success" @click="addCart(productObj.id)">购买</el-button>
        <el-button type="primary" @click="$router.push('/shopIndex')">返回首页</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import axios from "axios"

export default {
  data() {
    return {
      id: "",
      productObj: {},
    }
  },
  created() {
    this.findById();
  },
  methods: {
    findById() {
      this.id = this.$route.query.productId;
      axios.get("/project/product/findById", {params: {productId: this.id}}).then(resp => {
        this.productObj = resp.data;
      })
    },
    addCart(productId) {
      axios.get("/project/cart/addCart", {params: {productId}}).then(resp => {
        if (resp.data == "ok") {
          this.$router.push("/shopCart");
        }
      })
    },
  }
}

</script>

<style scoped>

</style>